package com.bluesky.drcp.persistence.dao.hibernate;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.bluesky.drcp.business.Plugin;
import com.bluesky.drcp.persistence.dao.PluginDao;

public class PluginDaoImpl extends HibernateDaoSupport implements PluginDao {
	
	public Plugin getByName(String name) {
		List list = getHibernateTemplate().find("from Plugin where name=?",
				name);
		if (list.isEmpty())
			return null;
		else
			return (Plugin) list.get(0);
	}

	public void insert(Plugin o) {
		if (o.getId() == null)
			o.setId(o.getName());

		getHibernateTemplate().save(o);
	}

	public void update(Plugin o) {
		getHibernateTemplate().update(o);
	}

	public void saveOrUpdate(Plugin o) {

		getHibernateTemplate().saveOrUpdate(o);

	}

	public void deleteById(String id) {
		Plugin p = get(id);
		getHibernateTemplate().delete(p);
	}

	public List getAll() {
		return getHibernateTemplate().find("from Plugin");

	}

	public Plugin get(String id) {
		return (Plugin) getHibernateTemplate().get(Plugin.class, id);
	}

}
